// pages/home/home/index.js
const app = getApp();
const ajax = app.myRequest()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2822189242,3164617848&fm=26&gp=0.jpg',
      'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2289845752,824364961&fm=26&gp=0.jpg',
      'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1386254119,1664337109&fm=26&gp=0.jpg',
    ],
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    swiperCurrent: 0,
    statusBar: app.globalData.statusBar,
    customBar: app.globalData.customBar,
    custom: app.globalData.custom,
    location: '',
    address:'',
    business:[
      {
        img: '/images/sike.png',
        store: 'MAX全民健身房',
        distance: '1.5'
      },
      {
        img: '/images/sike.png',
        store: 'MAX全民健身房',
        distance: '1.6'
      },
      {
        img: '/images/sike.png',
        store: 'MAX全民健身房',
        distance: '1.7'
      },
      {
        img: '/images/sike.png',
        store: 'MAX全民健身房',
        distance: '1.8'
      }
    ]
  },
  swiperChange(e) {
    let current = e.detail.current;
    // console.log(current, '轮播图')
    let that = this;
    that.setData({
      swiperCurrent: current,
    })
  },
  coach(e){
    console.log(e)
  },
  store(e){
    console.log(e)
  },
  getMap(){
    // console.log('111')
    let _this = this;
    wx.chooseLocation({
      success:function(res){
        console.log('map',res)
        _this.setData({
          address:res.address,
          latitude:res.latitude,
          longitude:res.longitude
        })
        _this.getHotVenue()
        _this.getHotCoach()
      }
    })
  },
  scroll(e){
    // console.log(e)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.position()
  },
  // 获取当前地理位置
  position(){
    var that = this
    wx.getLocation({
      success (res) {
        console.log('re',res)
        let latitude = res.latitude;
        let longitude = res.longitude;
        that.setData({latitude,longitude})
        wx.request({
          url:'https://apis.map.qq.com/ws/geocoder/v1/' + "?location=" + latitude + ',' +
          longitude + "&key=" + '5ASBZ-RDYC6-UCWS2-ENPLN-7ROKF-OVFNA' + "&get_poi=1",
          success:res=>{
            console.log('res',res)
            that.setData({
              address:  res.data.result.address,
            });
          }
        })
        that.getHotVenue()
        that.getHotCoach()
      }
     })
     
  },
  getHotVenue(){
    var longitude = this.data.longitude
    var latitude = this.data.latitude
    var _this = this
    ajax.getRequest('/content/indexGymnasium',{longitude,latitude}).then((res)=>{
      console.log(res.data.data.data)
      _this.setData({
        hotVenue : res.data.data.data
      })
      
    })
  },
  getHotCoach(){
    var longitude = this.data.longitude
    var latitude = this.data.latitude
    var _this = this
    ajax.getRequest('/content/indexCoach',{longitude,latitude}).then((res)=>{
      console.log(res)
      _this.setData({
        hotCoach : res.data.data.data
      })
    })
  },
  getLogo(){
    getRequest('/Content/indexBanner').then((res)=>{
      console.log(res)
    })
  },
  // 跳到场馆页
  // goVenue(e){
  //   console.log(e)
  //   var index = e.currentTarget.dataset.idx
  //   var name = this.data.hotVenue[index].naem
  //   wx.navigateTo({
  //     url:'/pages/venue/venueHome/index'
  //   })
  // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})